<template>
	<view class="index_menu" v-if="munuList">
		<view class="menu_container">
			<view class="menu_left">
				<block v-for="item,index in munuList.cs" :key="index">
					<view @tap="clickIndex(item.cs,index)"
						:class="[index == leftIndex ?'left_active active_boxleft left_txt':'left_txt']">{{item.name}}
					</view>
				</block>
			</view>
			<view class="menu_right">
				<!-- Loading -->
				<block v-if="loading">
					<view class="right_title">
						<view class="la-square-jelly-box">
							<view class="box"></view>
							<view class="box"></view>
						</view>
					</view>

				</block>
				<block v-else v-for="e,i in rightArr">
					<view class="right_title" :style="`background:${colorStr};`">
						<view class="title" @tap="clickInput(e.name)">
							{{e.name}}
						</view>
						<uni-icons type="right" size="20"></uni-icons>
					</view>
					<view class="right_txt" v-if="e.cs.length>0">
						<block v-for="re,ri in e.cs" :key="ri">
							<view class="min_txt" @tap="clickInput(re.name)">
								{{re.name}}
							</view>
							<!-- {{randomColor}} -->
						</block>						
					</view>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		name: "indexMenu",
		props: ["munuList"],
		data() {
			return {
				rightArr: [],
				leftIndex: 0,
				loading: true,
				colorStr: '',
			};
		},
		computed: {
			...mapState(['historyList'])
			// https://www.cnblogs.com/shashazhu/p/11611298.html
			// randomColor() {
			// 	console.log('----')
			// 	let str = "rgba(" + Math.floor(Math.random() * 256) + "," + Math.floor(Math.random() * 256) + "," + Math
			// 		.floor(Math.random() * 256) + "," + (Math.random() * 0.3 + 0.1) + ")";
			// 	this.colorStr = str;
			// 	console.log(this.colorStr)
			// }
		},
		watch: {
			leftIndex(value) {
				// console.log(this.colorStr)
				this.randomColor()
			}
		},
		created() {
			this.randomColor()
			setTimeout(() => {
				if (this.munuList) {
					this.loading = false;
					this.clickIndex(this.munuList.cs[0].cs, 0)
				}
			}, 2000)
		},
		methods: {
			// ...mapState(['historyList']),
			clickIndex(k, j) {
				this.rightArr = k;
				this.leftIndex = j;
				console.log(k, j)
			},
			clickInput(k){
				console.log(k)
				if(this.historyList.indexOf(k) == -1){
					this.$store.dispatch('setHisList',k)
				}
				
				uni.navigateTo({
					url:`../searchDetail/searchDetail?value=${k}`
				})
			},
			randomColor() {
				// console.log('----')
				let str = "rgba(" + Math.floor(Math.random() * 256) + "," + Math.floor(Math.random() * 256) + "," + Math
					.floor(Math.random() * 256) + "," + (Math.random() * 0.3 + 0.1) + ")";
				this.colorStr = str;
				// console.log(this.colorStr)
			}

		}
	}
</script>

<style lang="scss">
	.index_menu {
		width: 100%;
		padding-top: 100rpx;

		.menu_container {
			width: 100%;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			position: relative;

			.menu_left {
				width: 24%;
				height: 100%;
				// height: 100rpx;
				display: flex;
				flex-direction: column;
				background-color: #F1F3F4;
				position: fixed;

				.left_txt {
					width: 100%;
					height: 100rpx;
					text-align: center;
					line-height: 100rpx;
					// background-color: #F1F3F4;
					position: relative;
					font-size: 34rpx;
				}

				.left_active {
					background-color: #FFFFFF;
					font-weight: bold;
					animation: co_animation .5s linear;
				}

				.active_boxleft::after {
					content: " ";
					display: inline-block;
					width: 8rpx;
					height: 46rpx;
					border-radius: 30rpx;
					background: #FFC533;
					position: absolute;
					top: 4rpx;
					right: 10rpx;
					transform: translate(50%, 50%);

				}
			}

			.menu_right {
				width: 74%;
				min-height: 200rpx;
				background-color: #FFFFFF;
				position: absolute;
				left: 25%;

				.right_title {
					width: 94%;
					margin: 20rpx auto;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #FFF7F7;
					font-weight: 600;
					padding: 38rpx 0;
					border-radius: 10rpx;

					// margin: 20rpx 0;
					.title {
						font-size: 34rpx;
						margin-right: 10rpx;
					}
				}

				.right_txt {
					width: 94%;
					margin: 0rpx auto;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: space-around;

					.min_txt {
						padding: 10rpx 24rpx;
						margin-bottom: 16rpx;
						border: 1rpx solid #ccc;
						border-radius: 8rpx;
					}
				}
			}
		}
	}

	@keyframes co_animation {
		0% {
			transform: scale(1);
		}

		50% {
			transform: scale(.9);
		}

		100% {
			transform: scale(1);
		}
	}

	// loading

	.la-square-jelly-box,
	.la-square-jelly-box>.box {
		position: relative;
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box;
		box-sizing: border-box;
	}

	.la-square-jelly-box {
		display: block;
		font-size: 0;
		color: #fff;
	}

	.la-square-jelly-box.la-dark {
		color: #333;
	}

	.la-square-jelly-box>.box {
		display: inline-block;
		float: none;
		background-color: currentColor;
		border: 0 solid currentColor;
	}

	.la-square-jelly-box {
		width: 50px;
		height: 50px;
	}

	.la-square-jelly-box>.box:nth-child(1),
	.la-square-jelly-box>.box:nth-child(2) {
		position: absolute;
		left: 0;
		width: 100%;
		background-color: #ff585b;
	}

	.la-square-jelly-box>.box:nth-child(1) {
		top: -25%;
		z-index: 1;
		height: 100%;
		border-radius: 10%;
		-webkit-animation: square-jelly-box-animate .6s -.1s linear infinite;
		-moz-animation: square-jelly-box-animate .6s -.1s linear infinite;
		-o-animation: square-jelly-box-animate .6s -.1s linear infinite;
		animation: square-jelly-box-animate .6s -.1s linear infinite;
	}

	.la-square-jelly-box>.box:nth-child(2) {
		bottom: -9%;
		height: 10%;
		background: #000;
		border-radius: 50%;
		opacity: .2;
		-webkit-animation: square-jelly-box-shadow .6s -.1s linear infinite;
		-moz-animation: square-jelly-box-shadow .6s -.1s linear infinite;
		-o-animation: square-jelly-box-shadow .6s -.1s linear infinite;
		animation: square-jelly-box-shadow .6s -.1s linear infinite;
	}

	.la-square-jelly-box.la-sm {
		width: 16px;
		height: 16px;
	}

	.la-square-jelly-box.la-2x {
		width: 64px;
		height: 64px;
	}

	.la-square-jelly-box.la-3x {
		width: 96px;
		height: 96px;
	}

	/*
	 * Animations
	 */
	@-webkit-keyframes square-jelly-box-animate {
		17% {
			border-bottom-right-radius: 10%;
		}

		25% {
			-webkit-transform: translateY(25%) rotate(22.5deg);
			transform: translateY(25%) rotate(22.5deg);
		}

		50% {
			border-bottom-right-radius: 100%;
			-webkit-transform: translateY(50%) scale(1, .9) rotate(45deg);
			transform: translateY(50%) scale(1, .9) rotate(45deg);
		}

		75% {
			-webkit-transform: translateY(25%) rotate(67.5deg);
			transform: translateY(25%) rotate(67.5deg);
		}

		100% {
			-webkit-transform: translateY(0) rotate(90deg);
			transform: translateY(0) rotate(90deg);
		}
	}

	@-moz-keyframes square-jelly-box-animate {
		17% {
			border-bottom-right-radius: 10%;
		}

		25% {
			-moz-transform: translateY(25%) rotate(22.5deg);
			transform: translateY(25%) rotate(22.5deg);
		}

		50% {
			border-bottom-right-radius: 100%;
			-moz-transform: translateY(50%) scale(1, .9) rotate(45deg);
			transform: translateY(50%) scale(1, .9) rotate(45deg);
		}

		75% {
			-moz-transform: translateY(25%) rotate(67.5deg);
			transform: translateY(25%) rotate(67.5deg);
		}

		100% {
			-moz-transform: translateY(0) rotate(90deg);
			transform: translateY(0) rotate(90deg);
		}
	}

	@-o-keyframes square-jelly-box-animate {
		17% {
			border-bottom-right-radius: 10%;
		}

		25% {
			-o-transform: translateY(25%) rotate(22.5deg);
			transform: translateY(25%) rotate(22.5deg);
		}

		50% {
			border-bottom-right-radius: 100%;
			-o-transform: translateY(50%) scale(1, .9) rotate(45deg);
			transform: translateY(50%) scale(1, .9) rotate(45deg);
		}

		75% {
			-o-transform: translateY(25%) rotate(67.5deg);
			transform: translateY(25%) rotate(67.5deg);
		}

		100% {
			-o-transform: translateY(0) rotate(90deg);
			transform: translateY(0) rotate(90deg);
		}
	}

	@keyframes square-jelly-box-animate {
		17% {
			border-bottom-right-radius: 10%;
		}

		25% {
			-webkit-transform: translateY(25%) rotate(22.5deg);
			-moz-transform: translateY(25%) rotate(22.5deg);
			-o-transform: translateY(25%) rotate(22.5deg);
			transform: translateY(25%) rotate(22.5deg);
		}

		50% {
			border-bottom-right-radius: 100%;
			-webkit-transform: translateY(50%) scale(1, .9) rotate(45deg);
			-moz-transform: translateY(50%) scale(1, .9) rotate(45deg);
			-o-transform: translateY(50%) scale(1, .9) rotate(45deg);
			transform: translateY(50%) scale(1, .9) rotate(45deg);
		}

		75% {
			-webkit-transform: translateY(25%) rotate(67.5deg);
			-moz-transform: translateY(25%) rotate(67.5deg);
			-o-transform: translateY(25%) rotate(67.5deg);
			transform: translateY(25%) rotate(67.5deg);
		}

		100% {
			-webkit-transform: translateY(0) rotate(90deg);
			-moz-transform: translateY(0) rotate(90deg);
			-o-transform: translateY(0) rotate(90deg);
			transform: translateY(0) rotate(90deg);
		}
	}

	@-webkit-keyframes square-jelly-box-shadow {
		50% {
			-webkit-transform: scale(1.25, 1);
			transform: scale(1.25, 1);
		}
	}

	@-moz-keyframes square-jelly-box-shadow {
		50% {
			-moz-transform: scale(1.25, 1);
			transform: scale(1.25, 1);
		}
	}

	@-o-keyframes square-jelly-box-shadow {
		50% {
			-o-transform: scale(1.25, 1);
			transform: scale(1.25, 1);
		}
	}

	@keyframes square-jelly-box-shadow {
		50% {
			-webkit-transform: scale(1.25, 1);
			-moz-transform: scale(1.25, 1);
			-o-transform: scale(1.25, 1);
			transform: scale(1.25, 1);
		}
	}
</style>
